package com.os.opencv.java.chapter3;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class ConvertColor {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/test.jpg");
        HighGui.imshow("color", src);
        HighGui.waitKey(0);

        //将彩色图像转换为灰度图并在屏幕上显示
        Mat gray = new Mat();
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
        HighGui.imshow("gray", gray);
        HighGui.waitKey(0);

        //将图像转换为HSV颜色模型并在屏幕上显示
        Mat hsv = new Mat();
        Imgproc.cvtColor(src, hsv, Imgproc.COLOR_BGR2HSV);
        HighGui.imshow("hsv", hsv);
        HighGui.waitKey(0);

        //将图像转换为YUV颜色模型并在屏幕上显示
        Mat yuv = new Mat();
        Imgproc.cvtColor(src, yuv, Imgproc.COLOR_BGR2YUV);
        HighGui.imshow("yuv", yuv);
        HighGui.waitKey(0);

        System.exit(0);

    }
}
